#include #include "support.hh" // Function to calculate the gradient. I recommend you write the code // this way so that next week, when the gradient is not as trivial to // write your code will not need to change much. vector gradient(vector x, double y, vector w) { vector grad(w.dimension()); // Calculate gradient for single point and put into 'grad' vector return grad; } main() { // Read data into matrix 'x' matrix x(read_data("set1")); // # of rows of x is # of data points int points = x.rows(); vector y(points); // Put y's into separate vector, augment x vectors with -1 // (see problem set, problem #1) for (int i = 0; i < points; i++) { y[i] = x[i][2]; x[i][2] = -1; } // Put steepest descent loop here. Go through entire data set, // keeping cumulative sum of gradients at each point, then divide by // number of data points, multiply by learning rate and update // weights. Repeat until magnitude of change of weights drops below // some minimum value. // To calculate magnitude of some vector, use v.magnitude(); // Example of how to access data int trial = 10; cout << "Tenth data triplet: " << "x = {" << x[trial - 1][0] << ", " << x[trial - 1][1] << "}, y = " << y[trial - 1] << "\n"; // Print ten random numbers // random_number() returns a random # between -1 and 1 // Use it to initialize initial weight vector cout << "\nTen random numbers:\n"; for (i = 0; i < 10; i++) cout << random_number() << "\n"; }